﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Chunker.Inpe {
    class PngChunker {
        public static void ChunkFiles(string source) {
            string[] files = Directory.GetFiles(source, "*.png", SearchOption.TopDirectoryOnly);
            Dictionary<string, int> chunkCount = new Dictionary<string, int>();
            Dictionary<string, IChunk> chunks = new Dictionary<string, IChunk>();
            foreach (string file in files) {
                ChunkController chunker = new ChunkController();
                chunker.ChunkCreated += (sender, e) => {
                    if (chunkCount.ContainsKey(e.Chunk.Hash)) {
                        chunkCount[e.Chunk.Hash]++;
                    } else {
                        chunkCount.Add(e.Chunk.Hash, 1);
                    }
                    chunks.Add(e.Chunk.Hash, e.Chunk);
                };
                chunker.ChunkFile<Chunk>(file, 
                    ChunkController.WINDOW_SIZE,
                    ChunkController.MIN_CHUNK_SIZE,
                    ChunkController.MAX_CHUNK_SIZE,
                    ChunkController.DHASH);
            }
        }
    }
}
